/**
 * Created by Administrator on 2017/11/24 0024.
 */
var WfPowerSk = null;//风电场功率实况表
var WfDq = null;//风电场短期预报数据
var WfNwp = null;//风电场天气预报数据（取风速）
var WfMetSk = null;//测风塔数据表（取风速）
var WfDanjsWindSpeed = null;//单机风速
var InstallCapa = null;//装机容量
var Fan = null;
var startTime = null;       //开始时间，表格导出数据使用
var endTime = null;         //结束时间，表格导出数据使用
var farmName = null;       //电场名称，表格导出数据使用
var fileName = null;


$(function () {
    dateTiemSelect();//初始化日期格式
    $("#query").click(function () {
        queryButtonClick();
    })


    //farmName = $('#selectFarm', window.parent.document).text();//获取父页面的元素
    var aa = $('#selectFarm', window.parent.document).find("option:selected").text();
    console.log(aa);
    //  fileName = aa.substring(31,aa.length);
    // console.log(fileName);
    startTime = $("#startTime").val();
    endTime = $("#endTime").val();

    var table = new tableFactory(startTime,endTime,aa);



    //数据导出功能
    //by 孙延维02  20210313
    $('#export').on('click', function () {
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var farmid = $('#selectFarm', window.parent.document).val();//获取父页面的元素
        window.location.href="../shortPeriodManage/PowerForecastExpor?farmid="+farmid+"&startTime="+startTime+"&endTime="+endTime+"";
    });

})

/**点击查询按钮需要做的事情，由于多处用到所以将其抽出来作为一个方法
 * by 孙延维02 20210325
 * **/
function queryButtonClick(){
    if($("#startTime").val()===""||$("#endTime").val()===""){
        layer.msg("时间不完整！", {icon: 2});
        /**
         * bootstraptable自带表格的导出功能，要想导出的文件名称随时间选择改变就要先销毁创建的表格，再new新的表格
         * by孙延维02 20210318
         **/
        $("#shortPeriod").bootstrapTable("destroy");
        new tableFactory();
        return;
    }
    var startTime = new Date($("#startTime").val().replace(/\-/g, "\/"));
    var endTime = new Date($("#endTime").val().replace(/\-/g, "\/"));
    if(startTime >=endTime){
        layer.msg("开始时间不能大于结束时间！", {icon: 2});
        $("#startTime").val("");
        $("#endTime").val("");
        return false;
    }else {
        $("#shortPeriod").bootstrapTable("destroy");
        var farmid = $('#selectFarm', window.parent.document).find("option:selected").text();//获取父页面的元素
        var startTimeVal = $("#startTime").val();
        var endTimeVal = $("#endTime").val();
        new tableFactory(startTimeVal,endTimeVal,farmid);
        // load();
    }
}

//日期转换（时间戳转日期）
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
//点击查询，加载数据
//输入框设置主题。
function dateTiemSelect(){
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime', //新增的日期
            type: 'date',//日期类型date表示年月日
            /*  trigger: 'click',//如果绑定的元素非输入框，则默认事件为：click*/
            theme: '#071f3a',//自定义主题
            min: '2014-1-1',//限制最小日期
            max: '2029-12-31'//限制最大日期
        });
        laydate.render({
            elem: '#endTime', //新增的日期
            type: 'date',
            theme: '#071f3a',//自定义主题
        });
    });
}
//初始化加载曲线跟表格数据
function load(){

    var date = new Array();//观测时间
    var power =new Array();//实时功率
    var speed =new Array();//测风塔风速
    var title = new Array();//图例标题
    var arr =new Array();
    var forecastPower = new Array();//短期功率
    var weatherSpeed = new Array();//天气预报风速
    var danjiWindSpeed = new Array();//单机平均风速
    var farmid = $('#selectFarm', window.parent.document).val();//获取父页面的元素
    var p = {
        "startTime":$("#startTime").val(),
        "endTime":$("#endTime").val(),
        "farmid":farmid
    };
    var index = layer.load(0);
    $.ajax({
        url: "../shortPeriodManage/selectOption",
        type: "get",
        contentType: "application/json",
        dataType: "json",
        async: true,
        data: p/*JSON.stringify(p)*/,//转换成字符串。后台使用了RequestBody注解
        success: function (data) {
            layer.close(index);
            WfPowerSk = data.wfSkList;
            WfDq = data.wfDqlist;
            WfNwp = data.wfNwplist;
            WfMetSk = data.wfMetsklist;
            WfDanjsWindSpeed = data.wfDanjiWindspeedlist;
            InstallCapa =data.installcapa;//装机容量
            Fan = data.fan;
            if(InstallCapa==null){
                layer.msg("请设置装机容量！", {icon: 1});
                return;
            }
            $("#installcapa").val(InstallCapa+"mw");
            var newInstallCapa = parseFloat(InstallCapa);
            newInstallCapa+=2;     //by 孙延维02  20210313
            //console.log(WfDq);


            //风电场实况风速赋值
            $.each(WfPowerSk, function (index, item) {
                var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");

                power.push({name:time,value:[time,item.activepower.toFixed(2)]});
            });
            //风电场预报数据遍历
            $.each(WfDq, function (index, item) {
                var time = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm");
                forecastPower.push({name:time,value:[time,item.power.toFixed(2)]});//预报功率
            });
            //风电场天气预报风速遍历
            $.each(WfNwp, function (index, item) {
                var time = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm");
                weatherSpeed.push({name:time,value:[time,item.windspeed.toFixed(2)]});//天气风速
            });

            //风电场单机平均风速遍历
            $.each(WfDanjsWindSpeed, function (index, item) {
                var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                var newTime= time.split(":")[1];
                if(newTime%15 == 0){
                    danjiWindSpeed.push({name:time,value:[time,item.windspeed.toFixed(2)]});//单机风速
                }
            });

            //添加测风塔的风速
            if(Fan == 0){
                $.each(WfMetSk, function (index, item) {
                    var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                    if (item.windspeed != null) {
                        speed.push({name: time, value: [time, item.windspeed.toFixed(2)]});//天气风速
                    }
                });
            }else if(Fan == 1){
                $.each(WfMetSk, function (index, item) {
                    var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                    speed.push({name:time,value:[time,item.speed.toFixed(2)]});//天气风速
                });
            }


            lodaTu(date,power,title,speed,forecastPower,weatherSpeed,danjiWindSpeed,newInstallCapa);
            //farmName = $('#selectFarm', window.parent.document).text();//获取父页面的元素
            farmName = jQuery('#selectFarm', window.parent.document).find("option:selected").text();//获取父页面的元素

            fileName = farmName.substring(31,farmName.length);
            console.log(fileName);
            startTime = $("#startTime").val();
            endTime = $("#endTime").val();

            $("#shortPeriod").bootstrapTable("load", WfDq);
        }
    });


}

function reloadTable(){

    var date = new Array();//观测时间
    var power =new Array();//实时功率
    var speed =new Array();//测风塔风速
    var title = new Array();//图例标题
    var arr =new Array();
    var forecastPower = new Array();//短期功率
    var weatherSpeed = new Array();//天气预报风速
    var danjiWindSpeed = new Array();//单机平均风速
    var farmid = $('#selectFarm', window.parent.document).val();//获取父页面的元素
    var p = {
        "startTime":$("#startTime").val(),
        "endTime":$("#endTime").val(),
        "farmid":farmid
    };
    var index = layer.load(0);
    $.ajax({
        url : "../shortPeriodManage/selectOption",
        type : "get",
        contentType : "application/json",
        dataType : "json",
        async: true,
        data : p/*JSON.stringify(p)*/,//转换成字符串。后台使用了RequestBody注解
        success : function(data) {
            layer.close(index);
            WfPowerSk = data.wfSkList;
            console.log(data.wfSkList);
            WfDq = data.wfDqlist;
            WfNwp = data.wfNwplist;
            WfMetSk = data.wfMetsklist;
            WfDanjsWindSpeed = data.wfDanjiWindspeedlist;
            InstallCapa =data.installcapa;//装机容量
            Fan = data.fan;
            if(InstallCapa==null){
                layer.msg("请设置装机容量！", {icon: 1});
                return;
            }
            $("#installcapa").val(InstallCapa+"mw");
            var newInstallCapa = parseFloat(InstallCapa);
            newInstallCapa+=2;     //by 孙延维02  20210313
            //console.log(WfDq);


            //风电场实况风速赋值
            $.each(WfPowerSk, function (index, item) {
                var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");

                power.push({name:time,value:[time,item.activepower.toFixed(2)]});
            });
            //风电场预报数据遍历
            $.each(WfDq, function (index, item) {
                var time = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm");
                forecastPower.push({name:time,value:[time,item.power.toFixed(2)]});//预报功率
            });
            //风电场天气预报风速遍历
            $.each(WfNwp, function (index, item) {
                var time = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm");
                weatherSpeed.push({name:time,value:[time,item.windspeed.toFixed(2)]});//天气风速
            });

            //风电场单机平均风速遍历
            $.each(WfDanjsWindSpeed, function (index, item) {
                var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                var newTime= time.split(":")[1];
                if(newTime%15 == 0){
                    danjiWindSpeed.push({name:time,value:[time,item.windspeed.toFixed(2)]});//单机风速
                }
            });

            //添加测风塔的风速
            if(Fan == 0){
                $.each(WfMetSk, function (index, item) {
                    var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                    speed.push({name:time,value:[time,item.windspeed.toFixed(2)]});//天气风速
                });
            }else if(Fan == 1){
                $.each(WfMetSk, function (index, item) {
                    var time = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                    speed.push({name:time,value:[time,item.speed.toFixed(2)]});//天气风速
                });
            }

            var option = myChart.getOption();
            option.series[0].data = power;
            option.series[1].data = forecastPower;
            option.series[2].data = speed;
            option.series[3].data = weatherSpeed;
            option.series[4].data = danjiWindSpeed;
            myChart.setOption(option);
            // lodaTu(date,power,title,speed,forecastPower,weatherSpeed,danjiWindSpeed,newInstallCapa);
            //farmName = $('#selectFarm', window.parent.document).text();//获取父页面的元素
            farmName = jQuery('#selectFarm', window.parent.document).find("option:selected").text();//获取父页面的元素

            fileName = farmName.substring(31,farmName.length);
            console.log(fileName);
            startTime = $("#startTime").val();
            endTime = $("#endTime").val();

            $("#shortPeriod").bootstrapTable("load", WfDq);

            layer.close(index);
        }
    });


}


//表格工厂  给表格加上10米风向、10米风速、30米风向、30米风速、50米风向、50米风速等列 by孙延维02 20210313
function tableFactory(startTime,endTime,fileNames) {
    var me = this;
    me.data = null;//有功功率
    me.windData = null;//电站信息
    var init = function () {
        //$.when(me.getWindData()).then(function () {
        $("#shortPeriod").bootstrapTable({
            method: 'get',				  //请求方式（*）
            striped: true,					  //是否显示行间隔色
            cache: false,					   //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,				   //是否显示分页（*）
            sortable: true,					 //是否启用排序
            sortOrder: "desc",				   //排序方式
            sidePagination: "client",		   //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,					   //初始化加载第一页，默认第一页
            search: true,					   //是否显示表格搜索，只能进行客户端搜索
            strictSearch: false,                //true为全匹配，false为模糊查询
            showColumns: true,				  //是否显示筛选列按钮
            showRefresh: true,			  //是否显示刷新按钮
            clickToSelect:true,				//是否启用点击选中行
            showToggle: false,					//是否显示详细视图和列表视图的切换按钮
            cardView: false,					//是否显示详细视图
            detailView: false,				   //是否显示父子表
            singleSelect: true,                //是否支持多选,false表示支持多选，true表示不支持
            undefinedText: '',              //当数据为undefined时显示的字符
            height: 'auto',
            pageSize: 20,
            pageList: [5,20,30],
            editable:true,//是否可以行内编辑
            showExport: true,//是否显示导出按钮
            exportDataType:'all',//导出全部
            exportTypes:[  'csv'], //导出文件类型
            export: 'glyphicon-export icon-share',
            exportOptions:{
                // ignoreColumn: [0,1],  //忽略某一列的索引
                fileName:startTime+"_"+endTime+"_"+fileNames,  //文件名称设置
                // worksheetName: 'sheet1',  //表格工作区名称
                // tableName: '总台帐报表',
                //  excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                // onMsoNumberFormat: DoOnMsoNumberFormat
            },

            columns: [{
                title: '时间',
                field: 'foretime',
                sortable: true,//排序
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return new Date(parseInt(value)).Format("yyyy-MM-dd hh:mm");
                }/*,
                    editable: {
                        type:'datetime',
                        clear: false,
                        placement: 'left',
                        mode: "popup",//编辑框的模式：支持popup和inline两种模式，默认是popup
                        title: '请选择日期:',
                        format: 'yyyy-mm-dd hh:ii',
                        //viewformat: 'yyyy-mm-dd hh:ii',
                        //pickerPosition: "bottom-left",
                        datetimepicker: {
                            language: 'zh-CN',
                            weekStart: 1
                            //format: 'yyyy-mm-dd hh:ii'
                        }
                    }*/
            },{
                title: '实际功率(mw)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getSkPower(row.foretime);
                }/*,
                    editable: {
                        type: 'text',
                        mode: "popup",//编辑框的模式：支持popup和inline两种模式，默认是popup
                        title: '实际功率(mw)',
                        validate: function (v) {
                            var reg = /^[-+]?\d+$/;
                            if (!reg.test(v)) {
                                return '功率必须大于0';
                            }
                        }
                    }*/
            }, {
                title: '预报功率(mw)',
                field: 'power',
                align: 'center',
                width: '150',
                sortable: true,//排序
                valign: 'middle',
                formatter: function (value, row, index) {

                    if(row.power_fix==null||row.power_fix==0||row.power_fix=="0"){
                        return value.toFixed(2);
                    }else {
                        return row.power_fix.toFixed(2);
                    }

                },
                editable: {
                    type: 'text',
                    mode: "inline",//编辑框的模式：支持popup和inline两种模式，默认是popup
                    title: '短期功率(mw)',
                    sortable: true,//排序
                    validate: function (v) {
                        // var reg = /^[-+]?\d+$/;
                        // if (!reg.test(v)) {
                        //  return '格式不匹配';
                        //  }
                    }
                }
            }, /*{
                    title: '运行风机总数',
                    field: 'runCount',
                    align: 'center',
                    valign: 'middle',
                    sortable: true,
                    editable: {
                        type: 'text',
                        mode: "popup",//编辑框的模式：支持popup和inline两种模式，默认是popup
                        title: '风机总数',
                        validate: function (v) {
                           var result= /^[0-9]*[1-9][0-9]*$/;//正整数
                            if(result.test(v)===false) return '必须为整数';
                        }
                    }
                },*/{
                title: '测风塔风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfMetSkSpeed(row.foretime);
                }
            }, {
                title: '10米风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp10Speed(row.foretime);
                },
            },{
                title: '10米风向(°)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp10Direction(row.foretime);
                },
            },{
                title: '30米风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp30Speed(row.foretime);
                },
            },{
                title: '30米风向(°)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp30Direction(row.foretime);
                },
            },{
                title: '50米风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp50Speed(row.foretime);
                },
            },{
                title: '50米风向(°)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp50Direction(row.foretime);
                },
            },{
                title: '70米风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwpSpeed(row.foretime);
                },
            },{
                title: '70米风向(°)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwp70Direction(row.foretime);
                },
            },{
                title: '温度(℃)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwpTemp(row.foretime);
                },
            },{
                title: '气压(hPa)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwpPressure(row.foretime);
                },
            },{
                title: '湿度(%)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getWfNwpHumidity(row.foretime);
                },
            },{
                title: '原始预报(mw)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    // return row.power.toFixed(2);
                    return me.getYSPower(row.foretime);
                },
            },{
                title: '平均风速(m/s)',
                field: '',
                align: 'center',
                width: '150',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return me.getDanjiWindSpeed(row.foretime);
                },
            }],
            onEditableSave: function (field, row, oldValue, $el) {//编辑之后的事件
                var p ={
                    id:row.fid,
                    power:row.power
                }
                $.ajax({
                    type: "post",
                    url: "../shortPeriodManage/edit",
                    data:p,//后台使用了实体类，前台就不能用Json.stringify
                    dataType: 'JSON',
                    success: function (data, status) {

                    },
                    error: function () {
                        alert('编辑失败');
                    },
                    complete: function () {

                    }
                });
            }
        });
        load();
    }
    init();
}
tableFactory.prototype = {

    getWindById: function (farmid) {
        var farmName = '';
        var me = this;
        $.each(me.WindData, function (index, item) {
            if (item.farmid === farmid) {
                farmName = item.farmname;
                return false;
            }
        });
        return farmName;
    },
    /*获取实况功率*/
    getSkPower:function (time) {
        var power="";
        if(WfPowerSk.length>0){
            $.each(WfPowerSk, function (index, item) {
                if(new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm")==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    power = item.activepower.toFixed(2);
                    return false;
                }
            });
        }
        return power;
    },

    /*获取原始预报*/
    getYSPower:function (time) {
        var power="";
        if(WfDq.length>0){
            $.each(WfDq, function (index, item) {
                if(new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    power = item.power.toFixed(2);
                    return false;
                }
            });
            return power;
        }
        return power;
    },

    /*获取单机风速*/
    getDanjiWindSpeed:function (time) {
        var speed="";
        var compareTime = new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm");
        if(WfDanjsWindSpeed.length>0){
            $.each(WfDanjsWindSpeed, function (index, item) {
                var WfDanjiSpeedTime = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                if(WfDanjiSpeedTime==compareTime) {
                    if(item.windspeed == null){
                        return false;
                    }
                    speed = item.windspeed.toFixed(2);
                    return false;
                }
            });
            return speed;
        }
        return speed;
    },

    /*获取测风塔风速*/
    getWfMetSkSpeed:function (time) {
        var speed="";
        if(Fan == 0){
            if(WfMetSk.length>0){
                $.each(WfMetSk, function (index, item) {
                    var WfMetSkTime = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm");
                    if(WfMetSkTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                        speed = item.windspeed.toFixed(2);
                        return false;
                    }
                });
                return speed;
            }
        }else if(Fan == 1){
            if(WfMetSk.length>0){
                $.each(WfMetSk, function (index, item) {
                    var WfMetSkTime = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm")
                    if(WfMetSkTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                        speed = item.speed.toFixed(2);
                        return false;
                    }
                });
                return speed;
            }
        }

    },
    /*获取10米风速*/
    getWfNwp10Speed:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.windspeed10 == null){
                        return false;
                    }
                    speed = item.windspeed10.toFixed(2);
                    return false;
                }
            });
            return speed;
        }
        return speed;
    },
    /*获取10米风向*/
    getWfNwp10Direction:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.winddirection10 == null){
                        return false;
                    }
                    speed = item.winddirection10.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取30米风速*/
    getWfNwp30Speed:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.windspeed30 == null){
                        return false;
                    }
                    speed = item.windspeed30.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取30米风向*/
    getWfNwp30Direction:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.winddirection30 == null){
                        return false;
                    }
                    speed = item.winddirection30.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取50米风速*/
    getWfNwp50Speed:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.windspeed50 == null){
                        return false;
                    }
                    speed = item.windspeed50.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取50米风向*/
    getWfNwp50Direction:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.winddirection50 == null){
                        return false;
                    }
                    speed = item.winddirection50.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取70米风速*/
    getWfNwpSpeed:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    speed = item.windspeed.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取70米风向*/
    getWfNwp70Direction:function (time) {
        var speed="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    if(item.winddirection == null){
                        return false;
                    }
                    speed = item.winddirection.toFixed(2);
                    return false;
                }
            });
        }
        return speed;
    },
    /*获取温度*/
    getWfNwpTemp:function (time) {
        var temp="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    temp = item.temp.toFixed(2);
                    return false;
                }
            });
        }
        return temp;
    },
    /*获取气压*/
    getWfNwpPressure:function (time) {
        var pressure="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    pressure = item.pressure.toFixed(2);
                    return false;
                }
            });
        }
        return pressure;
    },
    /*获取湿度*/
    getWfNwpHumidity:function (time) {
        var humidity="";
        if(WfNwp.length>0){
            $.each(WfNwp, function (index, item) {
                var WfNwpTime = new Date(parseInt(item.foretime)).Format("yyyy-MM-dd hh:mm")
                if(WfNwpTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    humidity = item.humidity.toFixed(2);
                    return false;
                }
            });
        }
        return humidity;
    }
}



/*获取实况功率*/
function getSkPower (time) {
    var power="";
    if(WfPowerSk.length>0){
        $.each(WfPowerSk, function (index, item) {
            if(new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm")==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                power = item.activepower.toFixed(2);
                return false;
            }
        });
    }
    return power;
}


/*获取测风塔风速*/
function getWfMetSkSpeed(time) {
    var speed="";
    if(Fan == 0){
        if(WfMetSk.length>0){
            $.each(WfMetSk, function (index, item) {
                var WfMetSkTime = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm")
                if(WfMetSkTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    speed = item.windspeed.toFixed(2);
                    return false;
                }
            });
            return speed;
        }
    }else if(Fan == 1){
        if(WfMetSk.length>0){
            $.each(WfMetSk, function (index, item) {
                var WfMetSkTime = new Date(parseInt(item.observetime)).Format("yyyy-MM-dd hh:mm")
                if(WfMetSkTime==new Date(parseInt(time)).Format("yyyy-MM-dd hh:mm")) {
                    speed = item.speed.toFixed(2);
                    return false;
                }
            });
            return speed;
        }
    }

}

var myChart;
//折线图 日期，实况功率，图例，实况风速，预报功率
function lodaTu(date,power,title,speed,forecastPower,weatherSpeed,danjiWindSpeed,InstallCapa) {
    console.log(InstallCapa);
    myChart = echarts.init(document.getElementById("main"));
    var colors = ['#6eb2ff','#FF0000','#FFFF00','#00FF00','#6eb200'];
    option = {
        backgroundColor: '#071f3a',//背景色
        color: colors,
        //by 孙延维02  20210313  折线图鼠标移动到图标上面给数据加单位
        tooltip: {
            trigger: 'axis',
            formatter:function (c) {
                var str = '';
                var unit= {
                    '实际功率':'MW',
                    '预报短期功率':'MW',
                    '测风塔风速':'m/s',
                    '预报风速':'m/s',
                    '平均风速':'m/s'
                };

                c.forEach(function (item,index){
                    var value = item.value.toString();
                    if(value != null){
                        var newValue= value.split(",")[1];
                        if(index == 0){
                            str +=item.name + '</br>';
                        }
                        str +=item.marker+item.seriesName+':'+ newValue + ' ' + unit[item.seriesName]+'</br>';
                    }
                });
                return str;
            },
        },
        legend: {
            show:true,
            //orient:'horizontal',
            //borderWidth:2,
            selected: {
                '测风塔风速': false,
                '预报风速': false,
                '平均风速': false
            },
            data:[
                {
                    name:'实际功率',
                    textStyle:{
                        fontSize:12,
                        fontWeight:'bolder',
                        color:'#fff'
                    },
                    //icon:'image://../img/legend/1.png'//格式为'image://+icon文件地址'，其中image::后的//不能省略
                },
                {
                    name:'预报短期功率',
                    textStyle:{
                        fontSize:12,
                        fontWeight:'bolder',
                        color:'#fff'
                    },
                    // icon:'image://../img/legend/4.png'//格式为'image://+icon文件地址'，其中image::后的//不能省略
                },
                {
                    name:'测风塔风速',
                    textStyle:{
                        fontSize:12,
                        fontWeight:'bolder',
                        color:'#fff'
                    },
                    //icon:'image://../img/legend/3.png'//格式为'image://+icon文件地址'，其中image::后的//不能省略
                },
                {
                    name:'预报风速',
                    textStyle:{
                        fontSize:12,
                        fontWeight:'bolder',
                        color:'#fff'
                    },
                    //icon:'image://../img/legend/2.png'//格式为'image://+icon文件地址'，其中image::后的//不能省略
                },
                {
                    name:'平均风速',
                    textStyle:{
                        fontSize:12,
                        fontWeight:'bolder',
                        color:'#fff'
                    },
                    //icon:'image://../img/legend/2.png'//格式为'image://+icon文件地址'，其中image::后的//不能省略
                },
            ]
        },
        toolbox: {
            show: true,
            feature: {
                //mark: {show: true},
                //  dataZoom: {show: true},
                // dataView: {show: true},
                //  magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                //  restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: false,//取消拖拽
        dataZoom: {
            show: true,
            realtime: true,
            start: 0,
            end: 30
        },
        xAxis: [
            {
                //interval:0,//X轴的刻度间隔
                splitLine:{show: false},//去除网格线
                type: 'time',
                boundaryGap:true,
                //data: date,
                axisLabel:{
                    formatter: '{value}',
                    textStyle:{
                        fontWeight:"bolder",
                        color:"#fff"
                    }
                }
            }
        ],
        yAxis: [
            {
                splitLine:{show: false},//去除网格线
                name: '功率(mw)',
                max:InstallCapa,
                min:0,
                scale:true,
                nameTextStyle:{
                    color:'#fff'
                },
                type: 'value',
                axisLabel:{
                    formatter: '{value}'/*+'mw'*/,
                    textStyle:{
                        fontWeight:"bolder",
                        color:"#fff"
                    }
                }
            },
            {
                splitLine:{show: false},//去除网格线
                name: '风速(m/s)',
                max:30,
                min:0,
                scale:true,
                nameTextStyle:{
                    color:'#fff'
                },
                type: 'value',
                axisLabel:{
                    formatter: '{value}',
                    textStyle:{
                        fontWeight:"bolder",
                        color:"#fff"
                    }
                }
            }
        ],
        series: [
            {
                name: '实际功率',
                type: 'line',
                yAxisIndex: 0,
                symbol:'none',  //这句就是去掉点的
                data: power
            }, {
                name: '预报短期功率',
                type: 'line',
                yAxisIndex: 0,
                data: forecastPower,
                symbol:'none',  //这句就是去掉点的
                itemStyle:{
                    normal:{
                        lineStyle:{
                            width:2,
                            //type:'dotted'dashed  //'dotted'虚线 'solid'实线
                            //color: '#3300FF',
                            type: 'solid',
                            shadowBlur: 10,
                            shadowColor: 'rgba(0, 0, 0, 0.5)',
                            smooth:true,
                            width:2//线宽
                        }
                    }
                }

            },
            {
                name: '测风塔风速',
                type: 'line',
                yAxisIndex: 1,
                symbol:'none',  //这句就是去掉点的
                data: speed,

            },
            {
                name: '预报风速',
                type: 'line',
                yAxisIndex: 1,
                symbol:'none',  //这句就是去掉点的
                data:weatherSpeed,
                itemStyle:{
                    normal:{
                        lineStyle:{
                            width:2,
                            //type:'dotted'dashed  //'dotted'虚线 'solid'实线
                            //color: '#3300FF',
                            type: 'solid',
                            shadowBlur: 10,
                            shadowColor: 'rgba(0, 0, 0, 0.5)',
                            smooth:true,
                            width:2//线宽
                        }
                    }
                }
            },
            {
                name: '平均风速',
                type: 'line',
                yAxisIndex: 1,
                symbol:'none',  //这句就是去掉点的
                data:danjiWindSpeed,
                itemStyle:{
                    normal:{
                        lineStyle:{
                            width:2,
                            //type:'dotted'dashed  //'dotted'虚线 'solid'实线
                            //color: '#3300FF',
                            type: 'solid',
                            shadowBlur: 10,
                            shadowColor: 'rgba(0, 0, 0, 0.5)',
                            smooth:true,
                            width:2//线宽
                        }
                    }
                }
            }
        ]
    };
    myChart.setOption(option);
}





